<style>
  .layui-form-item .layui-input-company {
    width: auto;
    padding-right: 10px;
    line-height: 38px;
  }
</style>
<div class="layuimini-container layuimini-page-anim">
  <div class="layuimini-main">
    <form action="changepass" method="POST">
      <div class="layui-form layuimini-form">
        <div class="layui-form-item">
          <label class="layui-form-label required">用户名</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="username"
              name="username"
              lay-verify="required"
              lay-reqtext="用户名不能为空"
              placeholder="请输入新的用户名"
              value=""
              class="layui-input"
            />
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label required">新的密码</label>
          <div class="layui-input-block">
            <input
              type="password"
              id="password"
              name="password"
              lay-verify="required"
              lay-reqtext="密码不能为空"
              placeholder="请输入新的密码"
              value=""
              class="layui-input"
            />
          </div>
        </div>

        <div class="layui-form-item">
          <div class="layui-input-block">
            <button
              class="layui-btn layui-btn-normal"
              lay-submit
              type="submit"
              id="changeBtn"
              lay-filter="saveBtn"
            >
              提交修改
            </button>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>

<script>
  $.ajaxSetup({ cache: false });

  $("#changeBtn").click(function () {
    $user = $("#username").val();
    $password = $("#password").val();
    if (!$user || !$password) return;

    $.post("./changepass",{ username: $user, password: $password },
      function (data) {
        layer.msg(data.msg);
      }
    );
    return false;
  });
  layui.use(["form", "miniPage"], function () {
    var form = layui.form,
      layer = layui.layer,
      miniPage = layui.miniPage;

    /**
     * 初始化表单，要加上，不然刷新部分组件可能会不加载
     */
    form.render();

    //监听提交
    form.on("submit(saveBtn)", function (data) {
      var index = layer.alert(
        JSON.stringify(data.field),
        {
          title: "最终的提交信息",
        },
        function () {
          layer.close(index);
          miniPage.hashHome();
        }
      );
      return false;
    });
  });
</script>
